package com.zy.cat.entity.dev.repository;


import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import com.zy.cat.entity.dev.CatDevTreeTaskRecord;
import com.zy.cat.entity.dev.CatDevUserTaskRecord;
 
public interface CatDevTreeTaskRecordRepository extends JpaSpecificationExecutor<CatDevTreeTaskRecord>,  JpaRepository<CatDevTreeTaskRecord, String>{
	
	List<CatDevTreeTaskRecord> findByPidOrderByTaskType(String pid);
	
	List<CatDevTreeTaskRecord> findByPidAndTaskAttributeOrderByTaskType(String pid,int taskAttribute);
	
	List<CatDevTreeTaskRecord> findByPidAndTaskAttributeAndReceiveStatusOrderByTaskType(String pid,int taskAttribute,int receiveStatus);

	CatDevTreeTaskRecord findByPidAndTaskType(String pid,int taskType);
	
	@Query("from CatDevTreeTaskRecord where pid=:pid AND task_attribute=:taskAttribute AND DATE_FORMAT(ctime,'%Y-%m-%d')=CURRENT_DATE ORDER BY task_type")
	List<CatDevTreeTaskRecord> queryByPidAndTaskAttributeOrderByTaskType(String pid,int taskAttribute);
	
	@Query(nativeQuery = true,value = "select * from zy_cat_tree_task_record where pid=:pid AND task_type=:taskType order by ctime desc limit 1")
	CatDevTreeTaskRecord queryByPidAndTaskTypeOrderByTaskType(String pid,int taskType);

	/**
	 * @param pid
	 * @param i
	 * @param td_st_str
	 * @return
	 */
	@Query(nativeQuery = true,value = "select * from zy_cat_tree_task_record where pid=:pid AND task_attribute=:taskAttribute AND ctime=:ctime order by task_type asc")
	List<CatDevTreeTaskRecord> queryByPidAndTaskAttributeAndCtimeOrderByTaskType(String pid, int taskAttribute, String ctime);
}
